package thss.mro.simulate;

import java.util.Random;

import thss.mro.entity.Packet;
import thss.mro.entity.template.ProtocolTemplate;
import thss.mro.util.Constants;
import thss.mro.util.Protocol;
import thss.mro.util.QueryTester;
import thss.mro.util.Template;
import thss.mro.util.TypeTransUtil;

/**
 * 信元模拟数据生成器
 */
public class SCPCellGenerator extends Generator {

	/**
	 * 获得信元数据
	 */
	@Override
	public byte[] getData() {
		//初始化package
//		pack = new Packet();
		//获得SCP协议结构以生成数据
		Random random = new Random();
		int randomInt = random.nextInt(Template.SCPCellCodeLst.size());
		ProtocolTemplate scpCellHead = Protocol.getHeadTpl(Constants.PROTOCOL_NAME_SCPCELL);
		int cellCodeInt = Template.SCPCellCodeLst.get(randomInt);
		byte[] headData = TypeTransUtil.intToBytes(cellCodeInt);//SCP信元头部数据（信元编码）
		ProtocolTemplate scpCellBody = Template.getTemplate(Constants.TEMPLATE_ID_SCPCELL_BODY+cellCodeInt);
		byte[] bodyData = super.generateData(scpCellBody);//SCP信元正文数据
		byte[] rst = new byte[headData.length+bodyData.length];
		System.arraycopy(headData, 0, rst, 0, headData.length);
		System.arraycopy(bodyData, 0, rst, headData.length, bodyData.length);
		return rst;
	}
	
	@SuppressWarnings("static-access")
	public static void main(String[] args){
		//初始化
		Template t = new Template();
		QueryTester qt = new QueryTester();
		SCPCellGenerator cg = new SCPCellGenerator();
		for(int i=0;i<20;i++){
			byte[] data = cg.getData();
			qt.printHexString(data);
			System.out.println();
		}
	}

}
